home *** CD-ROM | disk | FTP | other *** search
- '--------------------------------------------------------------------------
- ' Progress.vbs - Shows how to use SG Window built-in dialog resources.
- '
- ' Progres sample shows how to open and close modeless dialog box. It opens
- ' dialog, creates progress bar control, waits some time and than closes
- ' progress dialog box.
- '
- ' REMARKS:
- '
- ' - dialog resource must be located in the file that can be loaded with
- ' Win32 LoadLibrary() function (EXE, DLL, ...) or you can use empty
- ' dialog template located in the SGWINDOW.DLL module. In this case
- ' pass empty string as a first parameter for the DoModal method and
- ' string "DLG_EMPTY" as a dialog template name.
- '
- ' This file is part of the SG Window.
- ' Copyright (C) 1998 Stinga
- ' All rights reserved.
- '--------------------------------------------------------------------------
- option explicit
-
- ' Messages
- const wm_CLOSE = &H0010&
- const wm_INITDIALOG = &H0110&
- const wm_COMMAND = &H0111&
-
- const PBM_SETRANGE = &H0401&
- const PBM_SETPOS = &H0402&
- const PBM_DELTAPOS = &H0403&
- const PBM_SETSTEP = &H0404&
- const PBM_STEPIT = &H0405&
- const PBM_SETRANGE32 = &H0406& ' lParam = high, wParam = low
- const PBM_GETRANGE = &H0407& ' wParam = return (TRUE ? low : high). lParam = PPBRANGE or NULL
- const PBM_GETPOS = &H0408&
-
- const PBS_SMOOTH = &H0001&
- const PBS_VERTICAL = &H0004&
-
- const ws_OVERLAPPED = &H00000000
- const ws_POPUP = &H80000000
- const ws_CHILD = &H40000000
- const ws_MINIMIZE = &H20000000
- const ws_VISIBLE = &H10000000
- const ws_DISABLED = &H08000000
- const ws_CLIPSIBLINGS = &H04000000
- const ws_CLIPCHILDREN = &H02000000
- const ws_MAXIMIZE = &H01000000
- const ws_CAPTION = &H00C00000
- const ws_BORDER = &H00800000
- const ws_DLGFRAME = &H00400000
- const ws_VSCROLL = &H00200000
- const ws_HSCROLL = &H00100000
- const ws_SYSMENU = &H00080000
- const ws_THICKFRAME = &H00040000
- const ws_GROUP = &H00020000
- const ws_TABSTOP = &H00010000
- const ws_MINIMIZEBOX = &H00020000
- const ws_MAXIMIZEBOX = &H00010000
- const ws_TILED = &H00000000
- const ws_ICONIC = &H20000000
- const ws_SIZEBOX = &H00040000
-
- const sMsg = "VBScript is working "
-
- ' Global declarations
- Dim g, dlg, wProgress, wStatic, i, rc, bCanceled
- Set g = WScript.CreateObject("SGWindow.Globals")
- Set dlg = WScript.CreateObject("SGWindow.Window", "dlg_")
- Set wProgress = WScript.CreateObject("SGWindow.Window")
- Set wStatic = WScript.CreateObject("SGWindow.Window")
-
- ' Show dialog
- ' Note that empty string as a resource module instructs
- ' SGWindow to use it's internal dialog resources.
- dlg.DoModeless "", "DLG_EMPTY", 100, 100
-
- ' Do something
- bCanceled = false
- for i = 0 to 1000 step 10
-
- ' Use Sleep method to give dialog box a chance to handle
- ' it's messages. Note that second parameter (true)
- ' instructs SGWindow to dispatch messages and events during
- ' sleep period.
- g.Sleep 20, true
-
- ' Update progress bar
- wProgress.SendMessage PBM_SETPOS, i, 0
- wStatic.Text = sMsg & CStr(i) & "/1000"
- if bCanceled Then
- MsgBox "Canceling at " & CStr(i) & "/1000"
- Exit For
- end if
- next
-
- ' Release objects
- Wscript.DisconnectObject dlg
- dlg.Destroy
- Set dlg = Nothing
- Set wProgress = Nothing
- Set wStatic = Nothing
- Set g = Nothing
-
- WScript.Quit
-
- '--------------------------------------------------------------------------
- ' Dialog window procedure
- '--------------------------------------------------------------------------
- Sub dlg_Message(msg, wParam, lParam, result)
- result = 0
- select case msg
- case wm_INITDIALOG
- ' Initialize and position dialog
- dlg.Text = "WSH Modeless Progress Bar"
- dlg.SetPosition 300, 300, 400, 150
-
- ' Create progress bar
- wProgress.Create "msctls_progress32", "", WS_CHILD + WS_VISIBLE + PBS_SMOOTH, 0, _
- 20, 20, dlg.Width-45, 25, dlg.hWnd, 100
- wProgress.SendMessage PBM_SETRANGE, 0, g.MakeLong(0, 1000)
-
- ' Create label
- wStatic.Create "STATIC", sMsg, WS_CHILD + WS_VISIBLE, 0, _
- 20, 50, 255, 25, dlg.hWnd, 101
-
- ' Create CANCEL button
- Dim w
- Set w = WScript.CreateObject("SGWindow.Window")
- w.Create "BUTTON", "Cancel", WS_CHILD + WS_VISIBLE + WS_TABSTOP, 0, _
- dlg.Width/2-50, dlg.Height-60, 100, 30, dlg.hWnd, 2
- w.hFont = dlg.hFont
- w.SetFocus
-
- case wm_CLOSE
- bCanceled = True
-
- case wm_COMMAND
- Dim bHandled
- bHandled = OnCommand(g.HighWord(wParam), g.LowWord(wParam), lParam)
- if Not bHandled Then
- result = dlg.CallWindowProc(msg, wParam, lParam)
- end if
-
- case else
- result = dlg.CallWindowProc(msg, wParam, lParam)
- end select
- End Sub
-
- '--------------------------------------------------------------------------
- ' Handle dialog WM_COMMAND messages
- '--------------------------------------------------------------------------
- Private Function OnCommand(notifyCode, id, hwnd)
- OnCommand = false
- select case id
- case 1 ' OK
- 'OnCommand = True
-
- case 2 ' CANCEL
- bCanceled = True
- OnCommand = True
-
- end select
- End Function
-
-